#!/bin/bash

yum -y update 
yum -y install socat minicom net-tools wget java-1.8.0-openjdk.x86_64 python3-pip
sed -i 's/TLS1\.[0-1],\s//g' /etc/java/java-1.8.0-openjdk/java-1.8.0-openjdk-1.8.0.312.b07-10.p01.ky10.x86_64/lib/security/java.security
sed -i 's/TLS1\.[0-1],\s//g' /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-10.p01.ky10.x86_64/jre/lib/security/java.security
pip3 install requests -i https://mirrors.aliyun.com/pypi/simple/
pip3 install supervisor
echo "[Unit]
Description=Process Monitoring and Control Daemon
After=rc-local.service nss-user-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/bin/supervisord -c /etc/supervisord.conf

[Install]
WantedBy=multi-user.target" > /lib/systemd/system/supervisord.service
systemctl daemon-reload
systemctl enable supervisord
echo "[unix_http_server]
file=/var/run/supervisor.sock

[supervisord]
logfile=/var/log/supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=info
pidfile=/var/run/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock

[include]
files = supervisord.d/*.ini

stopasgroup = true
killasgroup = true
" > /etc/supervisord.conf
mkdir /etc/supervisord.d
systemctl start supervisord
mkdir -p /data/server
mkdir -p /root/logs/iotp
echo "[program:iotp-server]
user=root
command=java -jar /data/server/server.jar -t 10011 -h 10012 -w 10013 -s 120 -l DEBUG
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/root/logs/iotp/server-out.log
stopasgroup=true
killasgroup=true" > /etc/supervisord.d/iotp-server.ini
wget https://res.codedance.top/iotp/server/server.jar -O /data/server/server.jar
supervisorctl reload